<html>
	
	<head>
		<meta charset="utf-8" />
		<title>商品列表</title>
	</head>

	<body>
		
		<a href="{:U('add_goods')}">添加商品</a>
	

		<table border="1" width="800">
			
			<tr>
				<th>名称</th>
				<th>描述</th>
				<th>详情</th>
				<th>价格</th>
				<th>数量</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
			<tbody id="goods_list">
<!-- 				<tr>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
					<td>1</td>
				</tr> -->
			</tbody>	


		</table>


	</body>

</html>
<script type="text/javascript" src="__PUBLIC__/js/jquery-2.1.0.js"></script>
<script type="text/javascript">
	
	var url = '{:U("goods_list")}';
	var data = {};

	//异步加载
	$.post(url,data,function(result){

		//示例返回数据
		// [
		//     {
		//         "id": "2",
		//         "goods_name": "苹果",
		//         "goods_img": "",
		//         "goods_desc": "大苹果",
		//         "goods_price": "100.00",
		//         "goods_detail": "大苹果好好吃",
		//         "goods_num": "100",
		//         "add_time": "1495957657",
		//         "update_time": "1495957657",
		//         "status": "1"
		//     }
		// ]

		var html = '';
		for(var i=0;i<result.length;i++){
			html += '<tr>';
			html += '<td>'+result[i].goods_name+'</td>';
			html += '<td>'+result[i].goods_desc+'</td>';
			html += '<td>'+result[i].goods_detail+'</td>';
			html += '<td>'+result[i].goods_price+'</td>';
			html += '<td>'+result[i].goods_num+'</td>';
			html += '<td>'+result[i].status+'</td>';
			html += '<td goods_id='+result[i].id+'><a class="act" status="-1">删除</a> <a href="/index.php/Admin/Goods/update_info?id='+result[i].id+'">修改</a> <a class="act" status="0">下架</a> <a class="act" status="1">上架</a></<td>';
			html += '</tr>';
		}

		$('#goods_list').append(html);
	});


	//删除事件
	$(document).on('click','.act',undefined,function(){
		//找到goods_id
		var goods_id = $(this).parent().attr('goods_id');

		var url = '{:U("change_status")}';
		var status = $(this).attr('status');
		var data = {
			'status':status,
			'id':goods_id
		};

		$.post(url,data,function(result){

			alert(result.msg);

			window.location.reload();
		});	


	});

	


</script>


